<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<meta charset="utf-8">
<head></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-invoiceApply-add">
        <div class="form-group">
            <label class="col-sm-2 control-label">纳税人号码：</label>
            <div class="col-sm-8">
                <input id="iaTaxpayerNum" name="iaTaxpayerNum" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">纳税人名字：</label>
            <div class="col-sm-8">
                <input id="iaTaxpayerName" name="iaTaxpayerName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">企业税号：</label>
            <div class="col-sm-8">
                <input id="bussinessNum" name="bussinessNum" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">购票手折：</label>

            <div class="col-sm-5">
                <!--id是给jquery使用的，name是给后台action使用的，必须和后台的名字相同！！ -->
                <input type="file" id="addUpload1" onchange="uploadFile('iaGpszPicture','1')" class="form-control"
                       accept="image/*"/>
                <input type="hidden" id="iaGpszPicture" name="iaGpszPicture"/>
            </div>
            <div class="col-sm-5">
                <img class="img-rounded" width="100" height="100" id="img1" class="img-thumbnail"/>
            </div>


        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">申请购买发票审批表：</label>
            <div class="col-sm-5">
                <!--id是给jquery使用的，name是给后台action使用的，必须和后台的名字相同！！ -->
                <input type="file" id="addUpload2" onchange="uploadFile('iaFpshPicture','2')" class="form-control"
                       accept="image/*"/>
                <input type="hidden" id="iaFpshPicture" name="iaFpshPicture"/>
            </div>
            <div class="col-sm-5">
                <img class="img-rounded" width="100" height="100" id="img2" class="img-thumbnail"/>
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">ic卡：</label>
            <div class="col-sm-5">
                <!--id是给jquery使用的，name是给后台action使用的，必须和后台的名字相同！！ -->
                <input type="file" id="addUpload3" onchange="uploadFile('iaIcCardPicture','3')" class="form-control"
                       accept="image/*"/>
                <input type="hidden" id="iaIcCardPicture" name="iaIcCardPicture"/>
            </div>
            <div class="col-sm-5">
                <img class="img-rounded" width="100" height="100" id="img3" class="img-thumbnail"/>
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">类型：</label>
            <div class="col-sm-8">
                <select id="iaType" name="iaType" class="form-control" type="text">
                    <option value="1">一般发票</option>
                    <option value="2">增值税专用发票</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">数量：</label>
            <div class="col-sm-8">
                <input id="iaCount" name="iaCount" class="form-control" type="number"/>
            </div>
        </div>
    </form>
</div>
>
<script type="text/javascript">
    var prefix = "${ctx}/system/apply"
    $("#form-invoiceApply-add").validate({
        rules: {
            iaTaxpayerName: {
                required: true,
                minlength: 2,
                maxlength: 20,
            },
            iaTaxpayerNum: {
                required: true,
                minlength: 2,
                maxlength: 20,
            },
            iaCount: {
                required: true,
                range: [1, 10000]
            },
            bussinessNum: {
                required: true,
                minlength: 2,
                maxlength: 20,
            }
        }
    });

    function submitHandler() {
        if (!$("#addUpload2").val() || !$("#addUpload3").val() || !$("#addUpload1").val()) {
            alert("请上传完整的图片");
            return;
        }
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-invoiceApply-add').serialize());
        }
    }


    function uploadFile(type, sort) {
        var formData = new FormData();
        formData.append("upload", $("#addUpload" + sort)[0].files[0]); //第一个file1代表后台文件属性名，第二个file1表示html中input的id
        $.ajax({
            type: "post",
            url: "${ctx}/file/upload",
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    $("#" + type).val(data.data.path);
                    $("#img" + sort).attr("src", "${ctx }/" + data.data.path);
                }
            },
            error: function (msg) {
                alert(msg.responsText);
            }
        });
    }
</script>
</body>
</html>
